{% extends "base.html" %}

{% block extra_head %}
    <link href="{{ static_url('css/mdeditor.min.css') }}" rel="stylesheet" type="text/css">
    <script src="{{ static_url('js/mdeditor.min.js') }}"></script>
        
{% end %}


{% block content %}

    <h2 class="text-center">{{ _("发表新博客") }}</h2>
    <div class="container">
        {% if blog_id %}
        <form method="post" action="/edit/{{ blog_id }}" class="form" onsubmit="return getHtml()" >
        {% else %}
        <form method="post" action="/edit" class="form" onsubmit="return getHtml()" >
        {% end %}
            {% raw xsrf_form_html() %}
            <div class="form-group">
                <label class="control-label">
                    {{ _('标题') }}    
                </label>
                <div class="">
                    <input type="text" name="title" class="form-control"  
                        value="{% if blog %}{{ blog['title'] }}{% end %}" />
                </div>                
            </div>
            <div class="form-group">
                <label class="control-label">
                    {{ _('简介') }}  
                </label>
                <div class="">
                    <input type="text" name="abstract" class="form-control" 
                        value="{% if blog %} {{ blog['abstract'] }} {% end %}" />
                </div>                
            </div>
            <div class="form-group">
                <label class="control-label">
                    {{ _('正文') }}    
                </label>
                <div id = "texthtmldiv" style="display:none">
                    <textarea rows="" cols="" name="texthtml" id='texthtml' ></textarea>
                </div>
                <div id = "wrap" style="height:300px;">
                </div>
                <script>
                    var editor = mdeditor({
                        id: 'wrap',
                        name: 'textmd'
                    });
                    
                    {% if blog %}
                        editor.setMarkdown({{ blog['textmd'] }});
                    {% end %}
                    
                    function getHtml()
                    {
                        texthtml = editor.getHTML();
                        $('#texthtml').html(texthtml);
                        return true;
                    }
                    
                </script>
            </div>
            <div class="form-group">
                <div class="">
                    <input type="submit" name="submit" id="submit" class="btn btn-primary" value="{{ _('提交') }}" />
                </div>
            </div>
        </form>
    </div>
    
{% end %}
